package demo11;

import sun.reflect.generics.tree.Tree;

import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

/**
 * 第十题: 通过代码, 完成如下需求:			//这个题不难, 就当送给大家的福利了. 江湖路远, 有缘再见, 顺祝大家早日找到理想工作, 高薪就业!
 * 1. 统计每个单词出现的次数
 * 2. 有如下字符串"If you want to change your fate I think you must come to the dark horse to learn java"(用空格间隔)
 * 3. 打印格式：
 * to=3
 * think=1
 * you=2
 * //........
 */
public class demo11 {
    public static void main(String[] args) {
        String s = "If you want to change your fate I think you must come to the dark horse to learn java";
        TreeMap<String, Integer> hm = new TreeMap<>((e1, e2) -> e1.compareTo(e2));
        String[] split = s.split(" ");
        for (String s1 : split) {
            if (hm.containsKey(s1)) {
                hm.put(s1, hm.get(s1) + 1);
            } else {
                hm.put(s1, 1);
            }
        }
        for (Map.Entry<String, Integer> entry : hm.entrySet()) {
            System.out.println(entry.getKey() + "=" + entry.getValue());
        }

    }
}
